﻿using System;
using Audit.Core;
using Serilog;
using Serilog.Events;

namespace Shared.Service.Logging.Serilog
{
    public class SerilogConfigurator : ISerilogConfigurator
    {
        internal Func<AuditEvent, ILogger> LoggerBuilder;
        internal Func<AuditEvent, LogEventLevel> LogLevelBuilder;
        internal Func<AuditEvent, object, object> MessageBuilder;

        public ISerilogConfigurator Logger(Func<AuditEvent, ILogger> loggerBuilder)
        {
            LoggerBuilder = loggerBuilder;
            return this;
        }

        public ISerilogConfigurator Logger(ILogger logger)
        {
            LoggerBuilder = _ => logger;
            return this;
        }

        public ISerilogConfigurator LogLevel(Func<AuditEvent, LogEventLevel> logLevelBuilder)
        {
            LogLevelBuilder = logLevelBuilder;
            return this;
        }

        public ISerilogConfigurator LogLevel(LogEventLevel logLevel)
        {
            LogLevelBuilder = _ => logLevel;
            return this;
        }

        public void Message(Func<AuditEvent, object, object> messageBuilder)
        {
            MessageBuilder = messageBuilder;
        }

        public void Message(Func<AuditEvent, object> messageBuilder)
        {
            MessageBuilder = (ev, _) => messageBuilder.Invoke(ev);
        }
    }
}
